{% extends "contact.html" %}
{% block body %}

    <div class="layui-container">
        <div class="layui-row">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>导航条</legend>
            </fieldset>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12" style="margin-bottom: 20px;">
                <span class="layui-breadcrumb">
                  <a href="/">首页</a>
                    <a href="JavaScript:;" onclick="JavaScript:history.go(-1);">全部文件夹</a>
                  <a><cite>{{ file_name }}</cite></a>
                </span>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <table class="table table-hover " id="mytable">
                    <thead>
                    <tr>
                        <th>文件名</th>
                        <th>创建时间</th>
                        <th>上传人</th>
                        <th>功能</th>
                        {% if super.super_user == 1 or my_space_super == 1 %}
                            <th>功能</th>
                        {% endif %}
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>

                </table>
            </div>
        </div>
        <div class="layui-row layui-fluid">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                <div id="demo7"></div>
            </div>
        </div>
    </div>
    <script>
        //面包屑需要依赖 element模块
        layui.use('element', function () {
            var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
        });
    </script>
    <script>
        // 分页样式发送ajax请求获取数据
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage
                , layer = layui.layer;
            //完整功能
            laypage.render({
                elem: 'demo7',
                count: {{ file_count }},
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
                jump: function (obj) {
                    $.ajax({
                        url: "{% url 'myadmin:File_Views' %}",//路径
                        type: "POST", //提交方式
                        data: {"page": obj.curr, "limit": obj.limit, 'file_name':'{{ file_name }}'},
                        success: function (result) {//返回数据根据结果进行相应的处理
                            $('#mytable>tbody>tr').remove();
                            let table_tr = '';
                            for (let i in result.data.file) {

                                table_tr += '<tr>';
                                table_tr += '<th>' +
                                    '<a href="/static/station/{{ file_name }}/' +
                                    result.data.file[i]["default_file_name"]+'">'+

                                    result.data.file[i]["default_file_name"]
                                    + '</a>' +
                                    '</th>';
                                table_tr += '<th>' + result.data.file[i]["create_time"] + '</th>';
                                table_tr += '<th>' + result.data.file[i]["name"] + '</th>';
                                table_tr +=  '<th>' +
                                    '<a href="/static/station/{{ file_name }}/' +
                                    result.data.file[i]["default_file_name"]+'"style="color:forestgreen" download="'+ result.data.file[i]["default_file_name"] +'">'
                                    + '下载</a>' +
                                    '</th>';
                                if (result.data.super == 1 || result.data.my_space_super == 1 ){
                                    table_tr += '<th>' +
                                        '<a href="javascript:" style="color:orangered" class="delete"' +
                                        'onclick=delete_1("'+ result.data.file[i]["default_file_name"] +'")>删除' +
                                        '</a></th>'
                                }
                            }
                            $('#mytable>tbody').append(table_tr)
                        },
                        error: function (error) {
                            layer.msg("500，请稍后尝试")
                        }
                    })
                }
            });
        });
    </script>
    <script>
        //文件夹删除
        function delete_1(file) {
            $.ajax({
                url: "{% url 'myadmin:File_One_Delete' %}",//路径
                type: "GET", //提交方式
                data: {"file_name": '{{ file_name }}', 'file': file},
                success: function (result) {//返回数据根据结果进行相应的处理
                    if (result.code = 200) {
                        layer.msg("删除成功！");
                        setTimeout(sleep, 1000);
                    }
                },
                error: function (error) {
                    layer.msg("500，请稍后尝试")
                }

            });
        }

        //定义一个函数
        function sleep() {
            window.location.reload();
        }

        // 返回顶部
        layui.use(['util', 'laydate', 'layer'], function () {
            var util = layui.util
                , laydate = layui.laydate
                , layer = layui.layer;
            //固定块
            util.fixbar({
                css: {right: 50, bottom: 100}
                , bgcolor: '#393D49'
                , click: function (type) {
                    console.log(type);
                    if (type === 'top') {
                        layer.msg('返回顶部')
                    }
                }
            });
        });

    </script>
{% endblock %}


